package test.upload;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

import org.junit.Test;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.Bucket;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;

public class simpleUpload {
	final String endpoint = "http://oss-cn-beijing.aliyuncs.com";
	final String accessKeyId = "I00vO1KPK9n40OCO";
	final String accessKeySecret = "aFOrRtRK4lCx44FyFxW1G8t1DyLQ6m";
//	final String accessKeyId = "AccessKeyId";
//	final String accessKeySecret = "AccessKeySecret";
//	final String endpoint = "http://oss-cn-beijing.aliyuncs.com";
	
	@Test
	public void upload() throws FileNotFoundException{
		// 创建OSSClient实例
		OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
		// 上传文件流
		InputStream inputStream = new FileInputStream("C:\\Users\\chuangye01\\Pictures\\ce3bb4ec8a136327dd3b9e9b998fa0ec0afac7ad.jpg");
		ossClient.putObject("hnxh", "aa/aaa/a/aaaa.jpg", inputStream);
		// 关闭client
		ossClient.shutdown();
	}
	
	@Test
	public void listBucket(){
		// 创建OSSClient实例
		OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);

		// 列举bucket
		List<Bucket> buckets = ossClient.listBuckets();
		for (Bucket bucket : buckets) {
		    System.out.println(" - " + bucket.getName());
		}
		// 关闭ossClient
		ossClient.shutdown();
	}
}
